package com.zyguo.thread;

import java.lang.Thread.State;

public class ThreadStatus {
	public static void main(String[] args) {
		final Thread t1 = new Thread( new SleepRunnable( 5000 ) ); 
		final Thread t2 = new Thread( new SleepRunnable( 10000 ) );
		System.out.println("new t1 status=" + t1.getState() );
		System.out.println("new t2 status=" + t2.getState() );
		
		Thread monitor = new Thread( new Runnable() {
			public void run() {
				//只要 t1 和  t2 有一个没停，就不停止监控
				while ( ! ( t1.getState() == State.TERMINATED && t2.getState() == State.TERMINATED ) ) {
					System.out.println("t1 status:" + t1.getState() + ",t=" + System.currentTimeMillis() );
					System.out.println("t2 status:" + t2.getState() + ",t=" + System.currentTimeMillis() );
					try {
						Thread.sleep( 1000 );
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				
				System.out.println("t1 status:" + t1.getState() + ",t=" + System.currentTimeMillis() );
				System.out.println("t2 status:" + t2.getState() + ",t=" + System.currentTimeMillis() );
				
			}
		} );
		
		monitor.start();
		t1.start();
		t2.start();
		
	} 
}

